package com.devmindset.legoframework.usage.client.monitors;

import com.devmindset.legoframework.client.mvc.EventMonitor;
import com.devmindset.legoframework.client.mvc.LegoEvent;
import com.devmindset.legoframework.client.mvc.LegoModel;
import com.devmindset.legoframework.client.mvc.metadata.EventMonitorStory;
import com.devmindset.legoframework.client.mvc.metadata.Stories;
import com.devmindset.legoframework.usage.client.component.FooterComponent;
import com.devmindset.legoframework.usage.client.component.HeaderComponent;
import com.devmindset.legoframework.usage.client.event.Events;

/**
 * Controller for common {@link SmartComponent}s used in different
 * {@link SmartScreen}s throughout the application.
 * 
 * @author <a href="ice.penov@devmindset.com">Ice Penov</a>
 */
public class CommonComponentMonitor extends EventMonitor {
	
	private HeaderComponent headerComponent = new HeaderComponent();
	private FooterComponent footerComponent = new FooterComponent();
	
	@Override
	public void handleEvent(LegoEvent event) {
		if (event.matches(Events.RENDER_HEADER_COMPONENT)) {
			headerComponent.render(new LegoModel(null));
		} else if (event.matches(Events.RENDER_FOOTER_COMPONENT)) {
			footerComponent.render(new LegoModel(null));
		}
	}

	public EventMonitorStory myStory() {
		return Stories.eventMonitor()
			.canHandle(
					Events.RENDER_HEADER_COMPONENT,
					Events.RENDER_FOOTER_COMPONENT
			)
			.knownAs("Common Component Monitor");
	}
	
}